package cn.ming.wfchat.app.me.activity;

import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.king.zxing.util.CodeUtils;

import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.AppService;
import cn.ming.wfchat.app.me.activity.model.RechargeBean;
import cn.ming.wfchat.kit.WfcBaseActivity;
import cn.wildfirechat.remote.ChatManager;

/**
 * @author luoming
 * created at 2020/8/11 3:04 PM
 * 充值
 */
public class MyAssetsTopUpActivity extends WfcBaseActivity {


    @BindView(R.id.iv_img)
    ImageView ivImg;
    @BindView(R.id.tv_privatekey)
    TextView tvPrivatekey;
    @BindView(R.id.btn_copy)
    Button btnCopy;

    @Override
    protected int contentLayout() {
        return R.layout.my_assets_top_up_activity;
    }

    @Override
    protected void afterViews() {
        super.afterViews();
        initDate();
    }

    void initDate() {
        String coinType = getIntent().getStringExtra("coinType");
        AppService.Instance().recharge(coinType, new AppService.RechargeCallback() {
            @Override
            public void onUiSuccess(RechargeBean rechargeBean) {
                Bitmap bitmap = CodeUtils.createQRCode(rechargeBean.getAddress(), 400);
                ivImg.setImageBitmap(bitmap);
                tvPrivatekey.setText(rechargeBean.getWalletAddress());
            }

            @Override
            public void onUiFailure(int code, String msg) {
                ChatManager.showToast(msg);
            }
        });
    }

    @OnClick(R.id.btn_copy)
    void setBtnCopy() {
        if (TextUtils.isEmpty(tvPrivatekey.getText().toString()))
            return;
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // 将文本内容放到系统剪贴板里。
        cm.setText(tvPrivatekey.getText().toString());
        ChatManager.showToast("复制成功");

    }
}
